package com.untils;

import javax.servlet.http.HttpServletResponse;

/**
 * 定义一个实体对象用来封装json数据后台返回值
 */
public class ResultantUtil {

    //两个返回的状态
    private static final int SUCCESS = HttpServletResponse.SC_OK;
    private static final int Fail = HttpServletResponse.SC_GONE;
    //成功与失败时的消息
    private static final String msg1 = "successful";
    private static final String msg2 = "succeed";

    private static Resultant resultant;

    //成功
    public  Resultant getSuccessResult() {
        resultant = new Resultant();
        resultant.setMessage(msg1);
        resultant.setFlag(SUCCESS);
        return resultant;

    }

    //成功，附带自定义数据
    public  Resultant getSuccessResult(String message) {
        resultant = new Resultant();
        resultant.setMessage(message);
        resultant.setFlag(SUCCESS);
        return resultant;

    }

    //成功，附带额外数据
    public  Resultant getSuccessResult(Object data) {
        resultant = new Resultant();
        resultant.setData(data);
        resultant.setMessage(msg1);
        resultant.setFlag(SUCCESS);
        return resultant;
    }

    //成功，自定义消息及数据
    public   Resultant getSuccessResult(String message,Object data) {
        resultant = new Resultant();
        resultant.setData(data);
        resultant.setMessage(message);
        resultant.setFlag(SUCCESS);
        return resultant;

    }

    //失败
    public  Resultant getFailResult() {
        resultant = new Resultant();
        resultant.setMessage(msg2);
        resultant.setFlag(Fail);
        return resultant;

    }

    //失败，附带消息
    public   Resultant getFailResult(String message) {
        resultant = new Resultant();
        resultant.setMessage(message);
        resultant.setFlag(Fail);
        return resultant;

    }

    //失败，自定义消息及数据
    public   Resultant getFailResult(String message, Object data) {
        resultant = new Resultant();
        resultant.setData(data);
        resultant.setMessage(message);
        resultant.setFlag(Fail);
        return resultant;

    }

    //自定义创建
    public Resultant getFreeResult(int code, String message, Object data) {
        resultant = new Resultant();
        resultant.setData(data);
        resultant.setMessage(message);
        resultant.setFlag(code);
        return resultant;
    }
}
